<?php

namespace Modules\WeChat\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\WeChat\Service\GoodsService;

class GoodsController extends Controller
{
    /**
     * 获取门店商品列表
     */
    public function goodsList(Request $request)
    {

        /*
                $s_openid = get_wat_token();
                $arr_user = wechat_user();
                $n_user_id = wechat_user_id();*/
        $data = get_wat_token();
        $res = GoodsService::goodsList($data);

        return response_json($res);
    }

    /**
     * 删除门店商品
     */
    public function delete(Request $request)
    {
        $data = $request->all();

        $res = GoodsService::delete($data);

        return response_json($res);
    }

    /**
     * 门店商品上下架
     */
    public function changeStatus(Request $request)
    {
        $data = $request->all();

        $res = GoodsService::changeStatus($data);

        return response_json($res);
    }

    /**
     * 添加门店服务商品
     */
    public function create(Request $request)
    {
        $data = $request->all();

        shiwu_start();
        $res = GoodsService::create($data);
        shiwu_end($res);

        return response_json($res);
    }

    /**
     * 获取门店服务商品详情
     */
    public function getDetail(Request $request)
    {
        $data = $request->get('id','');

        $res = GoodsService::getDetail($data);

        return response_json($res);
    }


    /**
     * 编辑门店服务商品
     */
    public function update(Request $request)
    {
        $data = $request->all();

        shiwu_start();
        $res = GoodsService::update($data);
        shiwu_end($res);

        return response_json($res);
    }

    /**
     * 获取服务商品分类列表
     */
    public function getType()
    {
        $res = GoodsService::getType();

        return response_json($res);
    }

    //wangEditor上传图片
    public function uploaded_file_wangEditor(){
        $res = upload_single_file($_FILES['file']);
        if ( $res['state'] == 0 ) {
            return ['errno'=>0,'data'=>[ $res['data']['url']],'msg'=>$res['msg']];
        }else{
            return ['errno'=>1,'data'=>[],'msg'=>$res['msg']];
        }
    }
}
